package sixth.Object类;

class Person1 {
    String name;
    int age;

    public Person1(String name, int age) {
        this.name = name;
        this.age = age;
    }
    //覆写toString()方法
    public String toString(){
        return "姓名："+this.name+"，年龄："+this.age;
    }
}

public class 应用toString方法取得对象内容 {
    public static void main(String[] args) {
        Person1 张一山 = new Person1("张一山", 88);
        System.out.println(张一山);//输出对象的时候调用的是子类覆写过的方法
    }
}
/*
D:\WorkSpaces\Java\jdk-21\bin\java.exe "-javaagent:D:\Software\IntelliJ IDEA\IntelliJ IDEA 2023.3.2\lib\idea_rt.jar=62408:D:\Software\IntelliJ IDEA\IntelliJ IDEA 2023.3.2\bin" -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8 -classpath D:\WorkSpaces\JavaDevelopBase_start_329\out\production\JavaDevelopBase_start_329 sixth.Object类.应用toString方法取得对象内容
姓名：张一山，年龄：88

Process finished with exit code 0

 */
